package com.hoppinzq.algorithm.graph;

/**
 * 有权边
 */
public class MyEdge implements Comparable<MyEdge>{
    private final int v;//边的一个顶点
    private final int w;//边的另一个顶点
    private final double weight;//权重

    public MyEdge(int v,int w,int weight){
        this.v=v;
        this.w=w;
        this.weight=weight;
    }

    /**
     * 返回边的权重
     * @return
     */
    public double getWeight(){
        return weight;
    }

    /**
     * 返回边的一个顶点
     * @return
     */
    public int either(){
        return v;
    }

    /**
     * 返回边的另一个顶点
     * @param vertex
     * @return
     */
    public int other(int vertex){
        if(vertex==v){
            return w;
        }else{
            return v;
        }
    }

    @Override
    public int compareTo(MyEdge that) {
        int c;
        //如果当前权重值大于传入的边的权重值，返回1
        if(this.getWeight()>that.getWeight()){
            c=1;
        }else if(this.getWeight()==this.getWeight()){
            c=0;
        }else{
            c=-1;
        }
        return c;
    }
}
